import {createStore,combineReducers,applyMiddleware} from './myredux'
// import thunk from 'redux-thunk'
import {thunk,logger} from './middle'
function count(state,action){
  state = state || {
    count:100
  }
  switch (action.type) {
    case 'add':
      return {
        count:state.count + action.num
      }
    case 'minus':
      return {
        count:state.count - action.num
      }
    default:
      return {
        ...state
      }
  }
}
function color(state,action){
  state = state || {
    color:'red'
  }
  switch (action.type) {
    case "changeColor":
      return {
        ...state,
        color:action.col
      }
  
    default:
      return {
        ...state
      }
  }
}

let rootReducer = combineReducers({
  countReducer:count,
  colorReducer:color
})

let store = createStore(rootReducer,applyMiddleware(logger,thunk))
// dispatch  getState  subscribe

export default store